import algoritmo as ga
import pandas as pd
from random import sample
import helpers


def get_genes_from(fn, sample_n=0):
    genes = []
    for n in range(1, len(helpers.read())+1):
      genes.append(ga.Gene(n,n))

    return genes if sample_n <= 0 else sample(genes, sample_n)

def read():
  data = pd.read_csv("cidades.txt", delimiter=';', header=None)
  nextRange = data.values[0][0] - 1
  length = data.values[0][0]
  tempData = []

  k = 1
  for i in range(length):
    tempData.append([])
    for j in range(nextRange):
      tempData[i].append(data.values[0][k])
      k += 1
    nextRange -= 1

  for count, value in enumerate(tempData):
    while len(tempData[count]) < length:
      tempData[count].insert(0, 0)
      
  matrix = [[0 for i in range(length) ] for j in range(length)]
  
  for line in range(len(tempData)):
    for column, value in enumerate(tempData[line]):
      if value != 0:
        matrix[line][column] = value
        matrix[column][line] = value

  # print(matrix)

  return matrix